<template>
  <div class="visit-total">
    <div class="slider-title">
      📈 关于/统计
      <div class="mac-style"></div>
    </div>
    <div class="visit-total-content pointer" @click="handleTo('/about/me')">
      <div class="visit-total-item total">
        <div class="label">🍦 今天访问</div>
        <div class="num num-f text">{{ state.blogVisitTotal.today || 1 }}</div>
      </div>
      <div class="visit-total-item total">
        <div class="label">🍧 昨天访问</div>
        <div class="num num-f text">{{ state.blogVisitTotal.yeasterday || 0 }}</div>
      </div>
      <div class="visit-total-item total">
        <div class="label">🍨 当月访问</div>
        <div class="num num-f text">{{ state.blogVisitTotal.currentMonth || 0 }}</div>
      </div>
      <div class="visit-total-item total">
        <div class="label">🧁 总访问量</div>
        <div class="num num-f text">{{ state.blogVisitTotal.sum || 0 }}</div>
      </div>
      <div class="visit-total-item">
        <div class="label">🌈 运行时间</div>
        <div class="time-wrap">
          <IconHour24 class="time-24" />
        </div>
        天
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { getBlogVisit } from '@/api/common';
import { reactive } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const state = reactive({
  blogVisitTotal: {
    today: 0,
    yeasterday: 0,
    currentMonth: 0,
    sum: 0
  }
});

// 获取博客访问统计
const getBlogVisitFn = () => {
  getBlogVisit().then(res => {
    if (res.code === 200) {
      state.blogVisitTotal = res.data;
    }
  });
};
getBlogVisitFn();

// 跳转关于我
const handleTo = (path: string) => {
  router.push({
    path
  });
};
</script>

<style lang="scss" scoped>
.visit-total {
  margin-top: 20px;
  background-image: linear-gradient(#ffffff00, #e3f4f5 10%, #ffb384 100%);
  .visit-total-content {
    padding: 20px;
    .visit-total-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: relative;
      height: 60px;
      color: #222;

      .label,
      .num {
        color: #222;
        font-size: 18px;
      }
      .time-wrap {
        position: absolute;
        top: -60px;
        right: 40px;
        width: 60px;
        height: 120px;
        padding: 60px 0 0 0;
        animation: swing 1.3s ease-in-out infinite alternate;
        display: flex;
        .time-24 {
          width: 60px;
          height: 60px;
        }
      }
    }
    .total {
      height: 30px;
    }
  }
}

@keyframes swing {
  0% {
    transform: rotate(18deg);
  }
  100% {
    transform: rotate(-18deg);
  }
}
</style>
